<div id="{{$pageID}}">
	<div class="mb10">
		 {{if $allow_add}}
			<?php echo $this->Html->link('<i class="glyphicon glyphicon-file"></i> '.__('Create New ').__d('modelextend',$current_model), 
array(
	'controller' => $current_controller,'plugin'=>$plugin,
	'action'=>'add','?'=>$this->request->query
),array(
	'date-title'=> __('Create New ').__d('modelextend',$current_model),
	'class'=>'btn btn-primary', 'target'=>'_blank',
	'id' => 'CreateNew'.$current_model,
	'escape'=>false)
); ?>{{/if}}


		 {{if in_array('cate_id',$table_fields)}}
	        	<div id="list-by-cate" class="btn-group">
			      <button class="btn btn-default dropdown-toggle"  data-toggle="dropdown" type="button"><i class="glyphicon glyphicon-search"></i> {{__('Category Filter')}}<span class="caret"></span></button>
			      
			      {{eval echo $this->Section->getLeftMenu('Category',
					array(
						'conditions'=>array('model'=> $current_model,'Category.visible'=>array(0,1) ),
						'parent_id'=>$site_cate_id,
						'ulAttributes'=> array('class'=>'dropdown-menu'),
						'selectedid' => $_GET['cate_id'],
						'subliAttributes2' => array('class'=>'dropdown-submenu'),
						'url' => 'javascript:;',
						'sufli'=>'<li class="search_container">
						<a class="ui-menu-first ui-corner-all" id="link-0" data-id="0" href="javascript:;" tabindex="-1">'.__('View All').'</a>
					</li>',
					));}}			      
			    </div>
	        {{/if}}
	      
	        {{if in_array('status',$table_fields)}}
	        	<div id="list-by-status" class="btn-group">
			      <button class="btn btn-default dropdown-toggle"  data-toggle="dropdown" type="button"><i class="fa fa-filter"></i> {{__('Status Filter')}}<span class="caret"></span></button>
			      <ul class="dropdown-menu">
				   {{loop $this->viewVars[statuses]  $k $v}}
				   	<?php if($k==='') continue; ?>
						<li><a href="javascript:;" data-status="{{$k}}"> {{$v}}</a></li>
					{{/loop}}
				  </ul>
			    </div>
	        {{/if}} 

			 {{$this->Hook->call('listToolbar',array(array('model'=>$current_model,'target_model'=>$target_model,'pageid'=>$pageID,'cname'=>$modelCname)))}}
	           <!-- 
	            {{if in_array('cate_id',$table_fields)}}
		             <li><?php echo $this->Html->link($modelCname.__('Categories'), array('controller' => 'categories','action'=>'list','model'=>$current_model),array('escape'=>false)); ?></li>
		        {{/if}}
	            <li><?php echo $this->Html->link(__('Search and Statistics'),'#',array('onclick'=>'return open_content_dialog(\'ui-search-form\');')); ?></li>
	             -->
	         
	         {{if in_array('published',$table_fields) && $allow_publish}}
		            <?php echo $this->Html->link('<i class="glyphicon glyphicon-cloud-upload"></i> '.__('Batch Publish'),'#',array('onclick'=>"return batchAction_{$pageID}('publish');",'class'=>'BatchPublish btn btn-success','escape'=>false)); ?>
		     {{/if}}
	            {{if $is_tree_model}}
		            {{if $allow_list}}
		            	<?php echo $this->Html->link(__('Normal List'), array('controller' => $current_controller,'action'=>'list','?'=>array('list'=>1)),array('escape'=>false,'class'=>'btn btn-primary','escape'=>false)); ?>
		            {{/if}}
		            <?php echo $this->Html->link(__('Tree Level Sort'), array('controller' => $current_controller,'action'=>'treesort','?'=>$this->request->query),array('escape'=>false,'class'=>'btn btn-primary','escape'=>false)); ?>
	            {{else}}
		            {{if in_array('deleted',$table_fields)}}
		            	{{if $allow_trash}}
			        		<?php echo $this->Html->link('<i class="glyphicon glyphicon-trash"></i> '.__('Batch Trash'),'#',array('onclick'=>"return batchAction_{$pageID}('trash');",'class'=>'BatchTrash btn btn-default hidden','escape'=>false)); ?>
		            	{{/if}}
		            	{{if $allow_restore}}
			            	<?php echo $this->Html->link('<i class="glyphicon glyphicon-refresh"></i> '.__('Batch Restore'),'#',array('onclick'=>"return batchAction_{$pageID}('restore');",'class'=>'BatchRestore btn btn-default hidden','escape'=>false)); ?>
			            {{/if}}
			            {{if $allow_delete}}
			            	<?php echo $this->Html->link('<i class="glyphicon glyphicon-remove"></i> '.__('Batch Delete'),'#',array('onclick'=>"return batchAction_{$pageID}('delete');",'class'=>'BatchDelete btn btn-warning hidden','escape'=>false)); ?>
			            {{/if}}
		            {{else}}
		            	<?php echo $this->Html->link('<i class="glyphicon glyphicon-remove"></i> '.__('Batch Delete'),'#',array('onclick'=>"return batchAction_{$pageID}('delete');",'class'=>'BatchDelete btn btn-warning hidden','escape'=>false)); ?>
		            {{/if}}
		        {{/if}}
		        
		        
				
				{{if $allow_fieldsetting || $allow_setting}}
				<div class="btn-group">
				  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
				    	<i class="glyphicon glyphicon-cog"></i> {{__('Setting')}} <span class="caret"></span>
				  </button>
				  <ul class="dropdown-menu" role="menu">
				   {{if $allow_fieldsetting}}
						<li><a onclick="return open_dialog({title:'{{__('List Fields')}}'},'{{$this->Html->url('/admin/settings/fieldsetting/'.$current_model.'/list_fields');}}',null,null,event);"><i class="glyphicon glyphicon-list"></i> {{__('List Fields');}}</a></li>
						<!-- <li><a onclick="return open_dialog({title:'{{__('Search Fields')}}'},'{{$this->Html->url('/admin/settings/fieldsetting/'.$current_model.'/search_fields');}}',null,null,event);"><i class="glyphicon glyphicon-search"></i> {{__('Search Fields');}}</a></li>
						 -->
					{{/if}}
					 <li class="divider"></li>
					{{if $allow_setting}}
						<li><a href="{{Router::url('/admin/settings/prefix/'.$current_model)}}" tabindex="-1" title="{{__('Param Settings')}}"><i class="glyphicon glyphicon-cog"></i> {{__('Param Settings')}}</a></li>
					{{/if}}
				  </ul>
				</div>
				{{/if}}
				<div class="pull-right">
					<a class="btn btn-default" target="_blank" href="{{$this->Html->url('/admin/'.$current_controller.'/import');}}" title="{{__('Import datas')}}"><i class="glyphicon glyphicon-circle-arrow-up"></i> </a>

					<a class="btn btn-default" id="export-with-option" title="{{__('Export datas')}}"><i class="glyphicon glyphicon-circle-arrow-down"></i> </a>

					<!-- {{if in_array('published',$table_fields)}}
						 <a class="btn btn-default"  href="#" onclick="goToUnPublish_{{$pageID}}();" ><i class="glyphicon glyphicon-send"></i> {{__('Not Published')}}</a>
					{{/if}} -->
					<button id="btn-all-list" type="button" class="btn btn-default active" onclick="goToDataList_{{$pageID}}();" title="{{__('All list')}}"><i class="glyphicon glyphicon-list"></i> </button>
					<button id="btn-recycle-list" type="button" class="btn btn-default" onclick="goToTrash_{{$pageID}}();" title="{{__('Recycle')}}"><i class="glyphicon glyphicon-trash"></i></button>
	           </div>
	           
	</div>
	
<!-- 
<div id="ui-search-form" class="dialog" title="{{__('Search and Statistics',true)}}" style="margin:0px 10px">		
	<div class="ui-search-form-content ui-corner-all">
	<form method="post" form_type="search"  onsubmit="return false;" action="/manage/webroot/index.php/admin/articles/list">
	
	<div id="groupby-info-{{$pageID}}">
		<fieldset>
		<div class="model-groupby-field ui-helper-clearfix select"><label for="-button">按组统计</label>
			<select name="data[][groupby][]"></select>
			<ul class="model-groupby-field-button groupby-field-{{$pageID}}">
			<li class="ui-state-default"><span class="ui-icon ui-icon-plus"></span></li>
			<li class="ui-state-default"><span class="ui-icon ui-icon-minus"></span></li>
			</ul>
		</div>
		</fieldset>
	</div>
	
	<div id="sumfields-info-{{$pageID}}">
	<fieldset>
		<div class="model-sum-field ui-helper-clearfix select">
			<label for="-button">求和统计</label>
			<select name="data[][sum][]">
			</select>
			<ul class="model-sum-field-button sum-field-{{$pageID}}">
			<li class="ui-state-default"><span class="ui-icon ui-icon-plus"></span></li>
			<li class="ui-state-default"><span class="ui-icon ui-icon-minus"></span></li>
			</ul>
		</div>
	</fieldset>
	</div>
	<div class="submit"><input type="submit" value="提交" class="ui-button ui-widget ui-state-default ui-corner-all"></div>
	</form>
	</div>
</div> -->

<script>
$(function(){
	$('#list-by-cate a').click(function(){
		var id = $(this).data('id'); 
		goToCate_{{$pageID}}(id)
	})
	$('#list-by-status a').click(function(){
		var status = $(this).data('status'); 
		goToStatus_{{$pageID}}(status)
	})
	
	$('.groupby-field-{{$pageID}} .ui-icon-plus').live('click',function(){
		obj = $(this).parents('.model-groupby-field:first');
		obj.clone().insertAfter(obj);
	});
	$('.groupby-field-{{$pageID}} .ui-icon-minus').live('click',function(){
		if($('#groupby-info-{{$pageID}} .model-groupby-field').size()>1){
			obj = $(this).parents('.model-groupby-field:first');
			obj.remove();
		}
	});
	$('.sum-field-{{$pageID}} .ui-icon-plus').live('click',function(){
		obj = $(this).parents('.model-sum-field:first');
		obj.clone().insertAfter(obj);
	});
	$('.sum-field-{{$pageID}} .ui-icon-minus').live('click',function(){
		if($('#sumfields-info-{{$pageID}} .model-sum-field').size()>1){
			obj = $(this).parents('.model-sum-field:first');
			obj.remove();
		}
	});
	
	$('input[type="submit"]','#{{$pageID}} .ui-search-form-content').bind('click',function(){
		var condition_str = ($('form','#{{$pageID}} .ui-search-form-content').serialize());
		//alert(condition_str);
		condition_str = condition_str.replace(/%5B%5D/g,'[]').replace(/data%5B/g,'conditions[').replace(/%5D%5B/g,'.').replace(/%5D/g,']');
		
		var hasgroup = false;
		$('#{{$current_model}}stats-info select').each(function(i){
				if(this.value!=""){
					hasgroup = true;
				}
			});
		if(hasgroup){
			$.get('{{$this->Html->url('/admin/ajaxes/groupby/');}}?{{$requeststr}}&'+condition_str+'&inajax=1',
					function(data){
						show_content(data)
					}
			);
		}
		else{
			//alert(condition_str);
			jQuery("#jqgrid_list").jqGrid('setGridParam',{url:'{{$this->Html->url('/admin/'.$current_controller.'/list.json');}}?{{$requeststr}}&'+condition_str,page:1}).trigger('reloadGrid');;
			$('.ui-search-form-close').trigger('click');
		}
		$("#ui-search-form").dialog("close");
		return false;
	});
	//$('.ui-search-form-close').trigger('click');
});



</script>

	<div class="clear ui-helper-clearfix"></div>
	<div id="pgtoolbar2_{{$pageID}}"></div> 
	<div id="pager2_{{$pageID}}"></div> 
	<table id="jqgrid_list_{{$pageID}}"></table>
<script>
//$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true; 
$.jgrid.ajaxOptions.dataType = "json";  // 保存等ajax交互动作返回json数据
var lastsel2_{{$pageID}};
var first_load_{{$pageID}} = true;
var mygrid_{{$pageID}}  = jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid({
   	"url":'{{Router::url('/admin/'.$current_controller.'/list.json');}}?{{$requeststr}}',
   	"editurl":'/admin/{{($this->plugin?$this->plugin.'/':'').$current_controller}}/edit',
   	"datatype":"json",
	"mtype": "POST", 
   	"colNames":[{{$col_names}}],//,'actions'
   	"colModel":[
   		{{$fieldlist}}	
   		//,{name:'act',index:'act', width:75,sortable:false} 	
   	],   	    	
   	"pager": '#pager2_{{$pageID}}',  
   	//"height":"auto",
   	{{if $is_tree_model}}
   	"rowNum":1000, // rowNum 要设置的足够大，防止取出的数据多时，在rowNum之后的无法显示。 
   	"rowList":[300,500,1000],
   	"treeGrid": true, 
   	"treeGridModel": 'nested',  // nested | adjacency  	
   	"ExpandColumn": 'name', 
   	"autowidth": true,
   	"ExpandColClick":true, 
   	'tree_root_level' : 0,
   	"treeReader" : {"level_field": "level","left_field":"left","right_field": "right","leaf_field": "isLeaf","expanded_field": "expanded","loaded":false},
   	{{else}}
   	"rownumbers":true, 
   	"multiselect":true,
  //"sortname": 'id',//默认排序字段在php中指定，含sort的字段默认按sort排序，其他为按id 
   	"sortorder": "desc",
   	"width":"850",
   	"rowNum":30,
   	"rowList":[15,30,50,100],
   	"hoverrows":true,
   	"viewrecords":true,
   	"xmlReader":{"repeatitems":false,"subgrid":{"repeatitems":false}},
   	{{/if}}
   	
   	"forceFit" : true, /* 列宽度字动匹配 */ 
    "jsonReader":{"repeatitems":false,"subgrid":{"repeatitems":false}},
	
	"afterInsertRow": function(rowid, aData){ 
    	
		switch (aData.published) { 
		  case true:
		  case '1': jQuery("#jqgrid_list_{{$pageID}}").jqGrid('setRowData',rowid,false,{color:'green'}); break; 
		  case false:
		  case '0': jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setRowData',rowid,false,{color:'#999'}); break; 
		// 未激活数据
		//case 'Client 3': jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setCell',rowid,'total','',{color:'blue'}); break; 
		} 
	},
	"onSelectRow":function(rowid,status,e){
		var ids = jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('getGridParam','selarrrow'); 
		if(ids == ""){
			$('.BatchTrash','#{{$pageID}}').addClass('hidden');
			$('.BatchPublish','#{{$pageID}}').addClass('hidden');
			$('.BatchRestore','#{{$pageID}}').addClass('hidden');
			$('.BatchDelete','#{{$pageID}}').addClass('hidden');
			return false;
		}
		else{
			{{if in_array('deleted',$table_fields)}}
				$('.BatchTrash','#{{$pageID}}').removeClass('hidden').show();
			{{else}}
				$('.BatchDelete','#{{$pageID}}').removeClass('hidden').show();
			{{/if}}
			$('.BatchPublish','#{{$pageID}}').removeClass('hidden').show();
			//$('.BatchRestore','#{{$pageID}}').removeClass('hidden').show();
			//
		}
	},
	/*"ondblClickRow": function(id){ 
		if(id && id!==lastsel2_{{$pageID}}){ 			
			jQuery('#jqgrid_list_{{$pageID}}','#{{$pageID}}').jqGrid('restoreRow',lastsel2_{{$pageID}}); 			
			lastsel2_{{$pageID}}=id; 
		} 
	},*/
	"loadComplete": function(ts,req){
		{{if $grid_action=='jqgridtree'}}
		// line 9683 expandNode =>  $(this).trigger("reloadGrid");
		// line 2289 bind('reloadGrid', function(e,opts) {
		// line 1638 populate = function (npage) {
		// line 7993  刷新grid if (o.refresh) {
		var ind2,pos;
		if(first_load_{{$pageID}}){ 
			$('.cell-wrapper').each(function(){ //cell-wrapper
				ind2 =$(this).closest("tr.jqgrow")[0].id;
				var obj = mygrid_{{$pageID}}.getLocalRow(ind2);				
				//$(obj).find("div.treeclick").trigger('click');
				mygrid_{{$pageID}}.expandRow(obj);
				mygrid_{{$pageID}}.expandNode(obj);
				
				// 仅在第一次加载，切层级小于3级时，自动展开.触发click事件不会自动加载数据，需要在数据已经加载完成的情况下。
				//$(this).find(".treeclick").trigger('click');		//.cell-wrapperleaf		
			})			
			first_load_{{$pageID}} = false;
		}
		{{/if}}
	}, 
	"gridComplete": function(){
		/*onDialogSubmitSucess,在page_loaded中，绑定form提交时间里*/
		$('#{{$pageID}} .ui-grid-actions a').bind('onDialogSubmitSucess',function(){
			reloadGrid_{{$pageID}}();
		});
		
		{{if $grid_action!='jqgridtree'}}
		$(".ui-jqgrid-bdiv",'#{{$pageID}}').scrollTop(jqgrid_scrollOffset); // 触发更新事件时，自动滚动到先前滚动条所在的位置。
		{{/if}}
		/*var ids = jQuery("#jqgrid_list_{{$pageID}}").jqGrid('getDataIDs'); 
		for(var i=0;i < ids.length;i++){ 
			var cl = ids[i]; 
			be = "<input style='height:22px;width:20px;' type='button' value='E' onclick=\"jQuery('#jqgrid_list_{{$pageID}}').editRow('"+cl+"');\" />"; 
			se = "<input style='height:22px;width:20px;' type='button' value='S' onclick=\"jQuery('#jqgrid_list_{{$pageID}}').saveRow('"+cl+"');\" />"; 
			ce = "<input style='height:22px;width:20px;' type='button' value='C' onclick=\"jQuery('#jqgrid_list_{{$pageID}}').restoreRow('"+cl+"');\" />"; 
			jQuery("#jqgrid_list_{{$pageID}}").jqGrid('setRowData',ids[i],{act:be+se+ce}); 
		} */
	}, 
    //"viewsortcols":[true,"horizontal",false],
    "idName":false,
    "caption":""
    ,toolbar: [true,"top"]
    
});
jQuery("#jqgrid_list_{{$pageID}}").jqGrid('navGrid','#pager2_{{$pageID}}',{edit:false,add:false,del:false},{},{},{},{multipleSearch:true, multipleGroup:true});
//jQuery("#jqgrid_list_{{$pageID}}").jqGrid('gridResize',{minWidth:350,minHeight:100});

/*
// 设置显示哪些列 
jQuery("#jqgrid_list_{{$pageID}}").jqGrid('navButtonAdd','#pager2_{{$pageID}}',{
	caption:"setColumns",title:"{{__('Set Display Columns')}}", 
	buttonicon :'ui-icon-extlink', 
	onClickButton:function(){
		// /admin/settings/fieldsetting/Article/list_fields 设置页面url，留存备忘  
		jQuery("#jqgrid_list_{{$pageID}}").jqGrid('setColumns',{columns:4,width:900,afterSubmitForm:function(obj){
			var postdata = '';
			obj.find('input[type="checkbox"]:checked').each(function(){
				postdata +='setting[{{$current_model}}][list_fields][]='+this.id.substr(4)+'&'; // col_id
			});
			ajaxAction('{{$this->Html->url("/admin/settings/ajaxesave/")}}',postdata); // ajax提交保存 
		}});
		return false;
	}
});
*/

$.fn.export2Excel= function(pager) {    
    $(this).navButtonAdd(pager,{id:"export_gridTable",caption:"导出",buttonicon:"ui-icon-arrowthickstop-1-s"});
}
$("#jqgrid_list_{{$pageID}}").export2Excel('#pager2_{{$pageID}}');  //添加导出按钮
$("#export_gridTable",'#{{$pageID}}').attr("title","export");//设置标题

$("#export_gridTable",'#{{$pageID}}').click(function() {
    //直接打开另一个页面导出
    var url = jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid("getGridParam","url");
    //alert(url);
    //var soptions = jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid("getGridParam","postData");
    //for(var i in soptions){
    	//alert(i+' '+soptions[i])
    //}
    url +='&export=true';
    window.open(url); 
});


$('#export-with-option','#{{$pageID}}').click(function(){

	var url = jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid("getGridParam","url");
	var soptions = jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid("getGridParam","postData");

	/*var str = '';
	for(var i in soptions){
    	str += (i+' '+soptions[i])+"\n";
    }
    alert(str);*/
    var url = '/admin/{{$current_controller}}/export_options';
    if(soptions.filters) {
    	url = '/admin/{{$current_controller}}/export_options?filters='+soptions.filters;
    }
	publishController.open_dialog(url,{title:'Export',width:960});
})

$('.ui-list-toolbar','#{{$pageID}}').appendTo($("#t_jqgrid_list_{{$pageID}}"));
$("#t_jqgrid_list_{{$pageID}}").height('auto');


/*  jqgird 列表进入某一分类   */
function goToCate_{{$pageID}}(id)
{
	$('.BatchTrash','#{{$pageID}}').removeClass('hidden').show();
	$('.BatchPublish','#{{$pageID}}').removeClass('hidden').show();
	$('.BatchRestore','#{{$pageID}}').addClass('hidden').hide();
	$('.BatchDelete','#{{$pageID}}').addClass('hidden').hide();
	if(id>0){
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{url:'{{$this->Html->url('/admin/'.$current_controller.'/list.json');}}?{{$requeststr}}&conditions[{{$current_model}}.cate_id]='+id,page:1}).trigger('reloadGrid');;
	}
	else{
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{url:'{{$this->Html->url('/admin/'.$current_controller.'/list.json');}}?{{$requeststr}}',page:1}).trigger('reloadGrid');;
	}
	return false;
}
	/*  jqgird 列表进入某一分类   */
	function goToStatus_{{$pageID}}(status)
	{
		$('.BatchTrash','#{{$pageID}}').removeClass('hidden').show();
		$('.BatchPublish','#{{$pageID}}').removeClass('hidden').show();
		$('.BatchRestore','#{{$pageID}}').addClass('hidden').hide();
		$('.BatchDelete','#{{$pageID}}').addClass('hidden').hide();
		
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{url:'{{$this->Html->url('/admin/'.$current_controller.'/list.json');}}?{{$requeststr}}&conditions[{{$current_model}}.status]='+status,page:1}).trigger('reloadGrid');;
		
		return false;
	}
/*  jqgird 列表相关操作函数  */
function goToTrash_{{$pageID}}()
{
	$('#btn-recycle-list','#{{$pageID}}').addClass('active');
	$('#btn-all-list','#{{$pageID}}').removeClass('active');
	
	$('.BatchTrash','#{{$pageID}}').addClass('hidden').hide();
	$('.BatchPublish','#{{$pageID}}').addClass('hidden').hide();
	$('.BatchRestore','#{{$pageID}}').removeClass('hidden').show();
	$('.BatchDelete','#{{$pageID}}').removeClass('hidden').show();
	{{if in_array('deleted',$table_fields)}}
	jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{url:'{{$this->Html->url('/admin/'.$current_controller.'/list.json');}}?{{$requeststr}}&conditions[{{$current_model}}.deleted]=1',page:1}).trigger('reloadGrid');
	{{else}}
	jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{url:'{{$this->Html->url('/admin/recycles/list/'.$current_model.'.json');}}?{{$requeststr}}',page:1}).trigger('reloadGrid');
	{{/if}}
}


function goToDataList_{{$pageID}}()
{
	$('#btn-recycle-list','#{{$pageID}}').removeClass('active');
	$('#btn-all-list','#{{$pageID}}').addClass('active');
	
	$('.BatchTrash','#{{$pageID}}').removeClass('hidden').show();
	$('.BatchPublish','#{{$pageID}}').removeClass('hidden').show();
	$('.BatchRestore','#{{$pageID}}').addClass('hidden').hide();
	$('.BatchDelete','#{{$pageID}}').addClass('hidden').hide();
	jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{url: '{{$this->Html->url('/admin/'.$current_controller.'/list.json');}}?{{$requeststr}}',page:1}).trigger('reloadGrid');;
}

function goToUnPublish_{{$pageID}}()
{
	$('.BatchTrash','#{{$pageID}}').removeClass('hidden').show();
	$('.BatchPublish','#{{$pageID}}').removeClass('hidden').show();
	$('.BatchRestore','#{{$pageID}}').addClass('hidden').hide();
	$('.BatchDelete','#{{$pageID}}').addClass('hidden').hide();
	jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{url:'{{$this->Html->url('/admin/'.$current_controller.'/list.json');}}?{{$requeststr}}&conditions[{{$current_model}}.published]=0',page:1}).trigger('reloadGrid');;
}
function reloadGrid_{{$pageID}}()
{
	var page = jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid("getGridParam","page");
	//scrollOffset = jQuery("#jqgrid_list_{{$pageID}}").jqGrid("getGridParam","scrollOffset");
	jqgrid_scrollOffset = $(".ui-jqgrid-bdiv",'#{{$pageID}}').scrollTop();	
	jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid("setGridParam",{page:page}).trigger("reloadGrid");
}
function deleteGridRow_{{$pageID}}(rowid)
{
	jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid("delRowData",rowid);
}
//进行行内编辑 ，若设置了flowstep_id则表示是流程中的授权操作  
function editGridRow_{{$pageID}}(id,flowstep_id)
{
	if(flowstep_id){
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{editurl:"{{$this->Html->url('/admin/flowsteps/dataedit/');}}"+flowstep_id+"/"+id});
	}
	else{
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridParam',{editurl:"{{$this->Html->url('/admin/'.($this->plugin?$this->plugin.'/':'').$current_controller.'/edit/');}}"+id});
	}
	jQuery('#jqgrid_list_{{$pageID}}','#{{$pageID}}').jqGrid('editRow',id,true); 
	$('#edit_grid_row_'+id,'#{{$pageID}}').hide();
	$('#save_grid_row_'+id,'#{{$pageID}}').show();
	$('#canceledit_grid_row_'+id,'#{{$pageID}}').show();
}
//进行行内编辑 ，若设置了flowstep_id则表示是流程中的授权操作  
function batchAction_{{$pageID}}(action,options)
{
	var ids = jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('getGridParam','selarrrow'); 
	if(ids == ""){
		alert($.jslanguage.noSelect);
		return false;
	}
	var appendargus = '?';
	if(options){
		for(var i in options){
			appendargus+= i+'='+options[i]+'&';
		}
	}
	
	var language='';
	if($.jslanguage['confirm_'+action]){
		language = $.jslanguage['confirm_'+action];
	}
	if(language!='' && !confirm(language)){
		return false;
	}
	//ids作为post传入，get参数可能造成url太长。url最多1K
	var postdata = '';
	for(var i in ids){
		postdata+='ids[]='+ids[i]+'&'
	}
	ajaxAction('{{Router::url('/admin/'.($this->plugin?strtolower($this->plugin).'/':'').$current_controller.'/');}}'+action+'.json'+appendargus,postdata,null,reloadGrid_{{$pageID}})
	//open_dialog({title:language},'{{Router::url('/admin/'.($this->plugin?strtolower($this->plugin).'/':'').$current_controller.'/');}}'+action+'/'+ids+'.json'+appendargus,reloadGrid_{{$pageID}});
	return false;
}
// 保存行内编辑数据 
function SaveGridRow_{{$pageID}}(id)
{
	jQuery('#jqgrid_list_{{$pageID}}','#{{$pageID}}').jqGrid('saveRow',id,function(res){			
			try{
				var obj=eval("("+res.responseText+")");
				if(obj.success && typeof(obj.success)=='xml'){
					throw "error";
				}
				if(obj.success){
					show_message(obj.success )
					return true;
				}
				else{
					var txt = "";  // 显示格式验证错误的信息  
					for(var i in obj){
						txt += obj[i]+"<br/>";
					}
					show_message(txt)
					return false;
				}
			}
			catch(err){				
			}
			return false;
		}); 
	$('#save_grid_row_'+id,'#{{$pageID}}').hide();
	$('#canceledit_grid_row_'+id,'#{{$pageID}}').hide();
	$('#edit_grid_row_'+id,'#{{$pageID}}').show();
}
// 取消编辑 
function CancelEditGridRow_{{$pageID}}(id)
{
	jQuery('#jqgrid_list_{{$pageID}}','#{{$pageID}}').jqGrid('restoreRow',id); 
	$('#save_grid_row_'+id,'#{{$pageID}}').hide();
	$('#canceledit_grid_row_'+id,'#{{$pageID}}').hide();
	$('#edit_grid_row_'+id,'#{{$pageID}}').show();
}

function resize_{{$pageID}}(){
	// 先调整高度，再调整宽度，防止调整高度出现滚动条，造成宽度有误差。（滚动条占一定的宽度）  
	// 先调整高度，再调整宽度，防止调整高度出现滚动条，造成宽度有误差。（宽度变化后，折行的内容会发生变化）（滚动条占一定的宽度）  
	obj = $('#{{$pageID}}').closest("#main-tab-content");
	if(obj.size()==0){
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid( 'setGridWidth',$('#mainContent').width() ); // window
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid( 'setGridHeight',$(window).height() - 160 ); 
	}
	else{
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridWidth',obj.width()-5);
		jQuery("#jqgrid_list_{{$pageID}}",'#{{$pageID}}').jqGrid('setGridHeight',$(window).height() - 260); //obj.height()-60
	}
	
	return;
}


$(document).ready(function(){
	/* 工具栏的提交事件 */
	$('#{{$pageID}} .nav-toolbar a').bind('onDialogSubmitSucess',function(){
		reloadGrid_{{$pageID}}();
	});
	
	resize_{{$pageID}}();
	$('#fg-button-{{$pageID}}').button({"icons":{"primary":'ui-icon-triangle-1-s'}} );
    //$('#fg-button-{{$pageID}}').unbind().menu({ content: $('#ul_categories_{{$pageID}}').html(), menuSelection:'#menuSelection-{{$pageID}}',flyOut: true });
});
</script>
</div> 

